package wangjg.commons.dao;

import java.lang.reflect.Method;
import java.util.LinkedHashMap;
import java.util.Map;

import org.springframework.aop.MethodBeforeAdvice;

/**
 * 
 * @author wangjg
 *
 */
public class SmartCacheQueryAdvice implements MethodBeforeAdvice{
	private int maxArgsNum = 2;
	private String methodPrefix = "find,query";
	private Map exeData = new LinkedHashMap(); 

	@Override
	public void before(Method method, Object[] args, Object target) throws Throwable {
		if(!isReadMethod(method.getName())){
			return;
		}
		String key = method.toGenericString();
		System.out.println(method.toGenericString() +"("+ args+")");
	}
	
	private boolean isReadMethod(String methodName){
		return methodName.startsWith("find")
			|| methodName.startsWith("query")
			|| methodName.startsWith("search")
			|| methodName.startsWith("get")
			|| methodName.startsWith("is")
			|| methodName.startsWith("load")
			|| methodName.startsWith("check")
			|| methodName.startsWith("verify")
		;
	}

}

class ExeData{
	String key;
	//执行总数
	int exeTotal;
	//参数变化
	int combination;
	//数据变化(命中率)
	
	//数据量
	long maxSize;
	long average;
}

/*
	<bean id="smartCacheQueryAdvice" class="com.gewara.gptbs.util.SmartCacheQueryAdvice" />
	
	<aop:config>
		<aop:advisor advice-ref="smartCacheQueryAdvice" pointcut="execution(public * com.gewara.gptbs.dao..*.*(..))" />
	</aop:config>
 */